let arr = [5, 6, 7, 8, 1, 2, 3];
arr.sort();
console.log(arr); // [1, 2, 3, 5, 6, 7, 8]

let strArr = ["zg", "aa", "cs", "lucy"];
strArr.sort();
console.log(strArr); // ['aa', 'cs', 'lucy', 'zg']

let objArr = [
  { name: 'kobe', age: 36, identifyCode: 100004 },
  { name: 'kobe', age: 36, identifyCode: 100003 },
  { name: 'kobe', age: 35, identifyCode: 100002 },
  { name: 'zg', age: 18, identifyCode: 100001 },
];
objArr.sort((a, b) => {
  if(a.name != b.name) {
    return a.name - b.name; // 名称字符大小排序
  } else if(a.age != b.age) {
    return a.age - b.age; // 年龄大小排序
  } else {
    return a.identifyCode - b.identifyCode; // 身份代码大小排序
  }
});
console.log(objArr);
/**结果
  {name: 'kobe', age: 35, identifyCode: 100002}
  {name: 'kobe', age: 36, identifyCode: 100003}
  {name: 'kobe', age: 36, identifyCode: 100004}
  {name: 'zg', age: 18, identifyCode: 100001}
*/
